<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Table</title>
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/global.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/table.css" />
</head>

<body>
<div class="admin-main">

    <blockquote class="layui-elem-quote">
        <a href="/admin/route/add" class="layui-btn layui-btn-small" id="add">
            <i class="layui-icon">&#xe608;</i>添加
        </a>
        <a href="javascript:;" class="layui-btn layui-btn-small" id="createSitemap">
            <i class="layui-icon">&#xe608;</i>生成sitemap.xml
        </a>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>路径重写</legend>
        <div class="layui-field-box layui-form">
            <table class="layui-table admin-table">
                <thead>
                <tr>
                    <th style="width: 30px;"><input type="checkbox" lay-filter="allselector" lay-skin="primary"></th>
                    <th>覆盖路径</th>
                    <th>被覆盖路径</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="content">
                <{php}>foreach($routeMap as $key => $val ){
                    echo "<tr>";
                        echo '<td><input type="checkbox" lay-skin="primary"></td>';
                        echo '<td>'.$key.'</td>';

                        echo '<td>'.$val.'</td>';
                        echo '<td>';
                            echo '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-mini delete" data-id="'.$key.'">删除</a>';
                        echo '</td>';
                    echo '</tr>';
                }
                <{/php}>

                </tbody>
            </table>
        </div>
    </fieldset>


</div>

<script type="text/javascript" src="/static/lib/layuiadmin/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/base64.js"></script>
<script>
    layui.use('layer',function(){
        var layer = layui.layer;
        var $ = layui.jquery;
        $(".delete").click(function(){
            var id = $(this).data('id');
            var base = new Base64();
            id = base.encode(id);

            $.ajax({
                url:'/admin/route/delete',
                type:'delete',
                data:{id:id},
                success:function(data){
                    if(data.code == 1){
                        layer.msg('<i class="layui-icon" style="font-size: 30px; color: #009688;">&#x1005;</i>'+data.msg,{},function(){location.reload();});
                    }else{
                        layer.msg('<i class="layui-icon" style="font-size: 30px; color: red;">&#x1006;</i>'+data.msg);
                    }
                }
            });

        });
        $("#createSitemap").click(function(){
            $.ajax({
                url:'/admin/route/createsitemap',
                type:'get',
                success:function(data){
                    layer.msg('<i class="layui-icon" style="font-size: 30px; color: #009688;">&#x1005;</i>'+data.msg);
                }
            });
        });
    });
</script>
</body>

</html>